package com.dddpeter.app.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dddpeter.app.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评论Mapper接口
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    
    /**
     * 根据文章ID查询评论列表（包含回复）
     */
    @Select("SELECT * FROM comments WHERE article_id = #{articleId} AND parent_id IS NULL ORDER BY created_at DESC")
    List<Comment> findCommentsByArticleId(@Param("articleId") Long articleId);
    
    /**
     * 根据父评论ID查询回复列表
     */
    @Select("SELECT * FROM comments WHERE parent_id = #{parentId} ORDER BY created_at ASC")
    List<Comment> findRepliesByParentId(@Param("parentId") Long parentId);
}
